<?php
error_reporting(0);
header("Content-type: text/html; charset=utf-8");
session_start();
require_once 'common/config.php';
require_once 'common/conn.php';
require_once 'common/function.php';
require_once 'db/account.db.php';
require_once 'db/item.db.php';
require_once 'db/itemType.db.php';
require_once 'db/accountMoney.db.php';
require_once 'db/friend.db.php';
require_once 'db/character.db.php';
require_once 'common/common.php';

// 当面付
// require_once './alipay/service/AliPayService.php';

/*
unset($_SESSION['AccUnique']);
unset($_SESSION['AccountID']);
unset($_SESSION['AccountPass']);
*/
//sprintf(param,"user_id=%s&user_pw=%s", g_BravoMain.m_cLoginID, g_BravoMain.m_cLoginPassMD5);//,pMsg->m_byErrStr, pMsg->m_byPhoneNumber);
//echo md5("123456");
// 开发模式开关 跳转链接拼接 ?GLuser_acc=ry01&GLuser_pwd=428b8076435bc1328d7f8aa4f89a65a7&job=0&alljob=1&key=Glmall0119&page=0&adjacents=4&type=1

if(DEBUG){
	if( isset($_GET['GLuser_acc']) )
	{
		$_SESSION['joinid'] = isset($_GET['GLuser_acc']) ? strval($_GET['GLuser_acc']) : "";
	}
	if( isset($_GET['GLuser_pwd']) )
	{
		$_SESSION['joinps'] = isset($_GET['GLuser_pwd']) ? strval($_GET['GLuser_pwd']) : "";
	}

	if( $_SESSION['AccountID'] == "" || $_SESSION['AccountPass'] == "" )//第一次POST进入，获取POST传值
	{
		$accountId = isset($_GET['GLuser_acc']) ? strval($_GET['GLuser_acc']) : "";
		if ($accountId == "") {
			$accountId = isset($_POST['GLuser_acc']) ? strval($_POST['GLuser_acc']) : "";
		}
		$accountPass = isset($_GET['GLuser_pwd']) ? strval($_GET['GLuser_pwd']) : "";
		if ($accountPass == "") {
			$accountPass = isset($_POST['GLuser_pwd']) ? strval($_POST['GLuser_pwd']) : "";
		}
	}else//以get方式跳回来 则取sesion///页面的切换
	{
		$accountId = isset($_GET['GLuser_acc']) ? strval($_GET['GLuser_acc']) : "";
		if ($accountId == "") {
			$accountId = isset($_POST['GLuser_acc']) ? strval($_POST['GLuser_acc']) : "";
		}
		if( $_SESSION['joinid'] != $_SESSION['AccountID'] )
		{
			unset($_SESSION['AccUnique']);
			unset($_SESSION['AccountID']);
			unset($_SESSION['AccountPass']);
			$accountId = $_SESSION['joinid'] ;
			$accountPass = $_SESSION['joinps'];
		}else{
			$accountId = $_SESSION['AccountID'];
			$accountPass = $_SESSION['AccountPass'];
		}
	}
}else{
	/*
	* 账号判定
	*/
	if( isset($_POST['GLuser_acc']) )
	{
		$_SESSION['joinid'] = isset($_POST['GLuser_acc']) ? strval($_POST['GLuser_acc']) : "";
	}
	if( isset($_POST['GLuser_pwd']) )
	{
		$_SESSION['joinps'] = isset($_POST['GLuser_pwd']) ? strval($_POST['GLuser_pwd']) : "";
	}

	if( $_SESSION['AccountID'] == "" || $_SESSION['AccountPass'] == "" )//第一次POST进入，获取POST传值
	{
		$accountId = isset($_GET['GLuser_acc']) ? strval($_GET['GLuser_acc']) : "";
		if ($accountId == "") {
			$accountId = isset($_POST['GLuser_acc']) ? strval($_POST['GLuser_acc']) : "";
		}
		$accountPass = isset($_GET['GLuser_pwd']) ? strval($_GET['GLuser_pwd']) : "";
		if ($accountPass == "") {
			$accountPass = isset($_POST['GLuser_pwd']) ? strval($_POST['GLuser_pwd']) : "";
		}
	}else//以get方式跳回来 则取sesion///页面的切换
	{
		$accountId = isset($_GET['GLuser_acc']) ? strval($_GET['GLuser_acc']) : "";
		if ($accountId == "") {
			$accountId = isset($_POST['GLuser_acc']) ? strval($_POST['GLuser_acc']) : "";
		}
		if( $_SESSION['joinid'] != $_SESSION['AccountID'] )
		{
			unset($_SESSION['AccUnique']);
			unset($_SESSION['AccountID']);
			unset($_SESSION['AccountPass']);
			$accountId = $_SESSION['joinid'] ;
			$accountPass = $_SESSION['joinps'];
		}else{
			$accountId = $_SESSION['AccountID'];
			$accountPass = $_SESSION['AccountPass'];
		}
	}
}

if( $accountId == "" || $accountPass == "")
{
	leError("账号信息获取失败，请重新打开商城");
	return;
}
/////////////////////////////////////////////////////

$job = isset($_GET['job']) ? strval($_GET['job']) : "";//玩家职业
$alljob = isset($_GET['alljob']) ? strval($_GET['alljob']) : "";//展示所有 默认0 不展示全部 1展示全部
if ($job == "") {
	$job = isset($_POST['job']) ? strval($_POST['job']) : "";
	if($job == "")
	{
		$job = -1;
	}
}
if($alljob == 1 )
{
	$xjob =-1;
}else
{
	//echo $job.'<br />';
	if($job != 0 && $job != 4 )
	{
		$yyjob = getAlljob($job);
		$xjob = $yyjob;
	}else
	{
		$xjob = $job;
	}
}
/*
  $key = isset($_GET['key']) ? strval($_GET['key']) : "";
  if ($key == "") {
  $key = isset($_POST['key']) ? strval($_POST['key']) : "";
  }
  if ($key != "Glmall0119") {
  return;
  }
*/
/*
  $paperDB = "paper3";
  $tgameDB = "BBGame_Test";
*/
$paperDB = "paper";
$tgameDB = "TGame_Test";
/*
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); //将出错信息输出到一个文本文件
*/
$dbc = new DBC();
$balance = 0;
//余额
$accountDb = new AccountDb($dbc);
$user = $accountDb->getAccountByAccountId($accountId);
if (isArrayNotEmpty($user)) {
	$pass = trim($user[0]['AccountPass']);
	$md5 = md5($pass);
	//echo " accountPass=[".$accountPass."]   pass=[".$pass."]  md5=[".$md5."]";
	if ($accountPass != $pass) {
		if(DEBUG){
			leError("账号密码错误".$pass);
		}
		return;
	}
	$_SESSION['AccUnique'] = $user[0]['AccUnique'];
	$_SESSION['AccountID'] = $user[0]['AccountID'];
	$_SESSION['AccountPass'] = $user[0]['AccountPass'];
	if (isset($_SESSION['AccountID']) && $_SESSION['AccountID'] != "") {
		$accountMoneyDb = new AccountMoneyDb($dbc);
		$accountMoney = $accountMoneyDb->getAccountMoney($_SESSION['AccUnique']);
		if ($accountMoney && isArrayNotEmpty($accountMoney)) {
			$balance = $accountMoney[0]['Balance'];
		}
	}
}
$itemDb = new ItemDb($dbc);
$page = isset($_GET['page']) ? intval($_GET['page']) : 0;
$adjacents = isset($_GET['adjacents']) ? intval($_GET['adjacents']) : 0;
if ($page <= 0) {
	$page = 1;
}
if ($adjacents <= 0) {
	$adjacents = 4;
}
$limit = 100;
$start = ($page - 1) * $limit;
if (isset($_GET['type'])) {
	$type = intval($_GET['type']);
} else {
	$type = 1;
}
$data = $itemDb->getItem($type, $start, $limit,$xjob);
$itemTypeDb = new ItemTypeDb($dbc);
$itemTypeArray = $itemTypeDb->getItemType();
$numberOfObject = $itemDb->getItemNumber($type);
$getSyAllcountdata = $itemDb->getSyAllcount($_SESSION['AccUnique']);
$getSendcountdata = $itemDb->getSendcount($_SESSION['AccUnique']);
$dbc2 = new DBC($paperDB);
$friendDb = new FriendDb($dbc2);
//file_put_contents("txt2.txt","11111111111111111111111111");
$friends = $friendDb->getFriendByAccount($_SESSION['AccUnique']);
//file_put_contents("txt.txt", json_encode($friends));
$friends_count = $friends ? count($friends) : 0;
$dbc3 = new DBC($tgameDB);
$characterDb = new CharacterDb($dbc3);
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title><?php echo TITLE;
		?></title>
	<link rel="stylesheet" href="./css/main.css">
	<link rel="stylesheet" href="css/dist/css/layui.css">
	<script src="css/dist/layui.js"></script>
	<!--[if lt IE 9]>
	<script src="js/html5shiv.min.js"></script>
	<script src="js/respond.min.js"></script>
	<![endif]-->
	<style>
		.yuanjiao{
			border-radius: 5px;
			/*behavior: url(PIE.htc);*/
			position: relative;
			z-index: 2;
		}
		.product_item .product_introl .product_props>a{
			border-radius: 5px;
			/*behavior: url(PIE.htc);*/
			position: relative;
			z-index: 2;
		}
		.product_item .product_introl .product_ctrl>a{
			border:1px solid #333;
			border-radius: 5px;
			/*behavior: url(PIE.htc);*/
			position: relative;
			z-index: 2;
		}
		.rechargeBtn {
        width: 75px;
		}
		.rechargeInput {
			width: 235px;
		}
	</style>
</head>
<body>
<div class="container">
	<div class="product_nav">
		<div class="dianshu yuanjiao">
                    <span class="dianshu_num">荣币：<span id="balance_show"><a href="javascript:void(0)" onclick="getSentCount();"><font color="#FFF0F5"><?php echo $balance;
									?></font></a></span></span>
			<!--<a href="http://new.shoukabao.cn/Payment/Service/ab68f07b19732d558922c58b00b36545" target="_blank" class="chongzhi_btn">在线充值</a>-->
			<!-- <a href="javascript:void(0)" class="chongzhi_btn yuanjiao" onclick="testgo();">在线充值</a> -->
			<a href="javascript:void(0)" class="chongzhi_btn yuanjiao" onclick="openRecharge();">在线充值</a>
		</div>
		<a href="store.php?type=1&job=<?php echo $job;  ?>&alljob=<?php echo $alljob; ?>" class="nav_btn zuixin yuanjiao"><i class="nav_icon"></i>最新商品</a>
		<a href="store.php?type=2&job=<?php echo $job;  ?>&alljob=<?php echo $alljob; ?>" class="nav_btn shizhuang yuanjiao"><i class="nav_icon"></i>角色时装</a>
		<a href="store.php?type=3&job=<?php echo $job;  ?>&alljob=<?php echo $alljob; ?>" class="nav_btn zuoqi yuanjiao"><i class="nav_icon"></i>坐骑装备</a>
		<a href="store.php?type=4&job=<?php echo $job;  ?>&alljob=<?php echo $alljob; ?>" class="nav_btn daoju yuanjiao"><i class="nav_icon"></i>功能道具</a>
		<a href="special.php?type=5&job=<?php echo $job;  ?>&alljob=<?php echo $alljob; ?>" class="nav_btn meiri yuanjiao"><i class="nav_icon"></i>每日专区</a>
		<a href="Point.php?type=6&job=<?php echo $job;  ?>&alljob=<?php echo $alljob; ?>" class="nav_btn jifen yuanjiao"><i class="nav_icon"></i>积分专区</a>
		<span class="layui-breadcrumb" lay-separator="-">
					<a href="javascript:void(0)"><font color="black">商品展示(点击选择):</font></a>

					<a id="cs1" href="store.php?type=<?php echo $_GET['type']; ?>&job=<?php echo $job;  ?>&alljob=0">当前职业:<font color="#ff5e0e"><?php echo
							$jobname = getJobName($job);
							$jobname; ?></font>(仅显示可用道具)</a>

					<a id="cs2" href="store.php?type=<?php echo $_GET['type']; ?>&job=<?php echo $job; ?>&alljob=1"><font color="green">所有职业</font></a>

				</span>
	</div>
	<script>
		//注意：导航 依赖 element 模块，否则无法进行功能性操作
		layui.use('element', function(){
			var element = layui.element;

			//…
		});

	</script>
	<script>
		function NoAccMsg() {
			//layer.msg('账号信息获取异常,请重新打开商城页面.', {icon: 1, time: 500000, offset: ['150px', '300px'], btn: ['知道了'], btnAlign: 'c'});
			alert('1');
		}
	</script>
	<div class="product_list">
		<?php
		$imageUrl = "./";
		for ($i = 0;$i < count($data);$i++) {
			$name = trim($data[$i]['ItemName']);
			$time_jieshao = trim($data[$i]['time_jieshao']);
			$alt = trim($data[$i]['alt']);
			$name = mb_convert_encoding($name, "UTF-8", "GBK");
			$time_jieshao = iconv("GBK", "UTF-8", $time_jieshao);
			$alt = iconv("GBK", "UTF-8", $alt);
			$dengji = iconv("GBK", "UTF-8", trim($data[$i]['dengji']));
			$wuligongji =iconv("GBK", "UTF-8", trim($data[$i]['wuligongji']));
			$mofagongji =iconv("GBK", "UTF-8", trim($data[$i]['mofagongji']));
			$wulifangyu =iconv("GBK", "UTF-8", trim($data[$i]['wulifangyu']));
			$mofafangyu =iconv("GBK", "UTF-8", trim($data[$i]['mofafangyu']));
			$mingzhong =iconv("GBK", "UTF-8", trim($data[$i]['mingzhong']));
			$huibi =iconv("GBK", "UTF-8", trim($data[$i]['huibi']));
			$liliang =iconv("GBK", "UTF-8", trim($data[$i]['liliang']));
			$minjie =iconv("GBK", "UTF-8", trim($data[$i]['minjie']));
			$zhihui =iconv("GBK", "UTF-8", trim($data[$i]['zhihui']));
			$hp = iconv("GBK", "UTF-8", trim($data[$i]['hp']));
			$mp = iconv("GBK", "UTF-8", trim($data[$i]['mp']));
			$type = trim($data[$i]['Type']);
			?>
			<div class="product_item">
				<div class="product_img_box">
					<img class="goods_hqid" data_id="<?php echo $i; ?>" id="image_<?php echo $i; ?>" src="<?php echo $imageUrl . $data[$i]['ImageUrl']; ?>"
						 title = "<?php echo $alt; ?>"
						 onclick="readxq(<?php echo $i; ?>,'<?php echo $dengji; ?>','<?php echo $wuligongji; ?>','<?php echo $mofagongji; ?>','<?php echo $wulifangyu; ?>','<?php echo $mofafangyu; ?>','<?php echo $mingzhong; ?>','<?php echo $huibi; ?>','<?php echo $liliang; ?>','<?php echo $minjie; ?>','<?php echo $zhihui; ?>','<?php echo $hp; ?>','<?php echo $mp; ?>','<?php echo $type; ?>');">
					<input type="hidden" id="number_xq" value=""/>
					<input type="hidden" id="item_<?php echo $i; ?>" value="<?php echo $data[$i]['ItemNo']; ?>" />
					<input type="hidden" id="idx_<?php echo $i; ?>" value="<?php echo $data[$i]['id_x']; ?>" />
					<input type="hidden" id="alt_<?php echo $i; ?>" value="<?php echo $alt; ?>" />
				</div>

				<div class="product_introl">
					<div class="detail_introl yuanjiao" id="name_<?php echo $i; ?>" data_value = "<?php echo $name;
					?>"><?php echo $name;
						?></div>
					<div class="product_props">
						<a href="javascript:void(0)" id="jieshao_<?php echo $i; ?>"><?php echo $time_jieshao;
							?></a>
						<a href="javascript:void(0)"><span id="price_<?php echo $i; ?>" data_value = "<?php echo $data[$i]['Price'];
							?>"><?php echo $data[$i]['Price'];
								?></span>荣币</a>
					</div>
					<div class="product_ctrl">
						<a href="javascript:void(0)" class="give" onclick="gift_send(<?php echo $i; ?>)">赠送</a>
						<a href="javascript:void(0)" class="buy" onclick="buy_sdj('<?php echo $i; ?>')">购买</a>
					</div>
				</div>
			</div>
			<?php
		} ?>
	</div>
</div>
<script>//

</script>
<div class="div_overlay" id="modal_div">
	<div id="popupdiv"  class="popupdiv zengsong">
		<div class="dialog_body">
			<div class="dialog_header">
				<p class="title_link"><img src="./images/arrow.png" alt="">购买道具</p>
				<span class="close_key"><img src="./images/close_caret.png" alt="" onclick="close_div()"></span>
			</div>
			<div class="dialog_content">
				<div class="product_detail">
					<div class="product_img_wrapper">
						<img class="product_img" id="current_image" src="" alt=""><!--这个是商品的渲染图片标签-->
						<input type="hidden" id="current_item" value="" />
						<input type="hidden" id="current_idx" value="" />
						<input type="hidden" id="current_price" value="" />
					</div>
					<div class="detail_introl_wrapper">
						<div><span clas="name_label">名称</span><span class="name_value" id="current_name"></span></div>
						<div class="detail_introl_txt" id="current_alt">
						</div>
					</div>
				</div>
				<div class="btn_group">
					<a href="javascript:void(0)" class="show_day"><span id="current_jieshao"></span><span id="show_price"></span> 荣币</a>
					<a href="javascript:void(0)" class="cancel" onclick="close_div()">取消</a>
					<a href="javascript:void(0)" class="confirm" onclick="confirm_buy()" id="confirm_button">确认赠送</a>
				</div>
			</div>
		</div>
		<div class="friends_list" id="select_div">
			<div class="friends_list_header">
				<img src="./images/user.png" alt="">赠送好友
			</div>
			<ul class="friends_list_ul">
				<!--<li onselect="selectli(this)" onclick="">ss</li>-->
				<?php
				for ($i = 0, $len = count($friends);$i < $len;$i++) {
					// $friends[$i]['FriendName'] = mb_convert_encoding(trim($friends[$i]['FriendName']), "UTF-8", "GBK");
					$name = trim($friends[$i]['FriendName']);
					$characters = $characterDb->getCharacterByName($name);
					if (count($characters) > 0) {
						$name = mb_convert_encoding($name, "UTF-8", "GBK");
						//echo "<option value='" . $characters[0]['AccountUnique'] . "'>$name</option>";
						echo "<li  onclick=\"selectli(this)\" onselect=\"selectli(this)\" id=\"" . $characters[0]['AccountUnique'] . "\">" . $name . "</li>";
					}
				}
				?>
			</ul>
		</div>
	</div>
</div>
<!--
		        <div class="div_overlay" id="modal_div">
		            <div class="product_item" style="margin: 25% 25%; background-color: wheat; opacity: 1.0;filter:Alpha(opacity=100);">
		                <div class="product_img_box" style="margin: 20px;">
		                    <img  id="current_image" src="" alt="">
		                    <input type="hidden" id="current_item" value="" />
		                    <input type="hidden" id="current_idx" value="" />
		                </div>
		                <div class="product_introl">
		                    <div class="detail_introl" id="current_name"><?php echo $name;
?></div>
		                    <div class="product_props">
		                        <a href="javascript:void(0)">半年</a>
		                        <a href="javascript:void(0)" id="current_price">点数</a>
		                    </div>
		                    <div class="product_ctrl">
		                        <a href="javascript:void(0)" class="give" onclick="close_div()">取消</a>
		                        <a href="javascript:void(0)" class="buy" onclick="confirm_buy()">确定</a>
		                    </div>
		                </div>
		                <div id="select_div" class="product_introl">
		                    <select id="friend_id" size="10" style="width:200px;">
		        <?php
for ($i = 0, $len = count($friends);$i < $len;$i++) {
	// $friends[$i]['FriendName'] = mb_convert_encoding(trim($friends[$i]['FriendName']), "UTF-8", "GBK");
	$name = trim($friends[$i]['FriendName']);
	$characters = $characterDb->getCharacterByName($name);
	if (count($characters) > 0) {
		$name = mb_convert_encoding($name, "UTF-8", "GBK");
		// echo "<option value='" . $characters[0]['AccountUnique'] . "'>$name</option>";
	}
}
?>
		                    </select>
		                </div>
		            </div>
		        </div>
		        -->
</body>
<script src="./js/jquery-1.11.3.js"></script>
<script src="./js/layer.js"></script>
<script>
	$(function() {
			$(document).ready(function() {
					$(document).bind("contextmenu", function(e) {
							return false;
						}
					);
				}
			);
			$('.product_list>.product_item:nth-child(3n+1)').css({
				//   marginLeft: '0'
			});
		}
	);
</script>
<script>
	var payInterval = null
	// 可以进行查询
	var payIntervalStatus = true
	var queryOutTradeNo = null
	var rechargeModal = null
	function testgo() {
		layer.msg('游戏目前处于研发学习阶段</br>如有赞助请联系QQ:719079746 </br> (赞助费用将全部用于日常维护和二次研发)', {icon: 2, time: 500000, offset: ['150px', '300px'], btn: ['确认'], btnAlign: 'c'});
		//window.open("http://shop.qx680.com/rechargeOrder.html")
		//layer.msg('你赠送的道具已发送至朋友的右下角 MY ITEM，请提醒他查收',5);
	}
	function getSentCount()
	{
		layer.msg('购买未满足累计剩余盒子数量：'+'<?php echo $getSyAllcountdata[0]['AllCount']; ?>'+'</br>'+'已获得赠送的深红宝石数量：'+'<?php echo $getSendcountdata[0]['SendCount']; ?>'+'</br>'+'已消耗进行兑换的礼盒数量：'+'<?php echo ($getSendcountdata[0]['SendCount']*166*0.5); ?>', {icon: 6, time: 500000, offset: ['150px', '300px'], btn: ['确认'], btnAlign: 'c'});
	}
	function clickMoneyBtn(money){
		document.getElementById('rechargeNumber').value = money;
	}

	function payStatusRefresh(){
		window.location.reload(true)
	}

	function queryPayStatus(){
		payIntervalStatus = false
		$.ajax({
			type: "POST",
			url: "api/recharge.php",
			dataType: "json",
			data: {
				action: 'queryRecharge',
				payGame: "YH",
				payGameVer: "RG",
				payGameOpt: "A",
				outTradeNo: queryOutTradeNo
			},
			success: function(data) {
				// alert("code" + data.code)
				// alert("payStatus" + data.payStatus)
				if (data.code == 0) {
					payIntervalStatus = true
					if(data.payStatus === 'TRADE_SUCCESS'){
						// 已扫码支付成功
						document.getElementById('payStatusDislpay').innerHTML = "已支付完成";
						document.getElementById('payStatusDislpay').style.color = "#00FF00";

						// 页面出现刷新按钮
						document.getElementById('payStatusRefreshBtn').style.display = "block";
						
						// 清除轮询
						clearInterval(payInterval);

						// 刷新页面
						setTimeout(function() {
							window.location.reload(true)
						}, 3000);
						// 提示成功
						layer.msg(
							'支付成功, 若余额未刷新请重新打开商城即可', 
							{
								icon: 1, 
								time: 3000, 
								offset: ['150px', '200px'], 
								btn: ['充值完成'], 
								btnAlign: 'c',
								yes: function(index, layero){
									window.location.reload(true)
									layer.close(index);
								}
							}
						);
					}else if(data.payStatus === 'TRADE_CLOSED'){
						// 已结束订单
						clearInterval(payInterval);
						window.location.reload(true)
						
					}else if(data.payStatus === 'TRADE_FINISHED'){
						// 已结束订单
						clearInterval(payInterval);
						window.location.reload(true)
					}
					payIntervalStatus = true
				}else{
					payIntervalStatus = true
				}
			},
			error: function(error, ab, cd) {
				payIntervalStatus = true
				clearInterval(payInterval)
				window.location.reload(true)
			}
		});
	}
	function generateRechargeQr()
	{
		click_status = false;
		loadding = layer.msg('支付码生成中,请稍后...', {
			icon: 16,
			time: 600000
			,shade: [0.8, '#393D49'],
			offset: ['250px', '300px']
		});
		if(!document.getElementById('rechargeNumber') || !document.getElementById('rechargeNumber').value || document.getElementById('rechargeNumber').value < 1){
			layer.msg('请输入正确的赞助金额(不低于5元)');
			return;
		}else if(document.getElementById('rechargeNumber').value > 2000){
			layer.msg('超过2000元请联系客服进行赞助(大额转账免手续费)');
			return;
		}
		// 支付二维码创建
		$.ajax({
				type: "POST",
				url: "api/recharge.php",
				dataType: "json",
				data: {
					action: 'generateRechargeQrCodeUrl',
					payGame: "YH",
					payGameVer: "RG",
					payGameOpt: "A",
					// payAmount: document.getElementById('rechargeNumber').value > 0 ? document.getElementById('rechargeNumber').value * 100 : 0
					payAmount: document.getElementById('rechargeNumber').value > 0 ? document.getElementById('rechargeNumber').value * 100 : 0
				},
				success: function(data) {
					click_status = true;//放开点击
					layer.close(loadding);
					if (data.code == 0) {
						queryOutTradeNo = data.outTradeNo
						// 隐藏充值选项
						document.getElementById('rechargeSelect').style.display = "none";
						document.getElementById('rechargeSelect2').style.display = "block";
						// 显示充值码
						document.getElementById('rechargeImg').src = data.imgUrl;
						// 显示金额
						document.getElementById('rechargeNumDisplay').innerHTML = document.getElementById('rechargeNumber').value + "元";
						document.getElementById('recharExtMoneyNumDisplay').innerHTML = Math.floor(document.getElementById('rechargeNumber').value * 6 / 1000 * 100)/100 + "元";
						document.getElementById('rechargeAllMoney').innerHTML = Math.floor(document.getElementById('rechargeNumber').value * (1006) / 1000 * 100)/100 + "元";
						
						payInterval = setInterval(function(){
							if(payIntervalStatus){
								queryPayStatus();
							}
						}, 4000);
					} else {
						document.getElementById('rechargeSelect').style.display = "block";
						document.getElementById('rechargeSelect2').style.display = "none";
						//                        alert(data.msg);
						layer.msg(data.msg, {icon: 5, time: 500000, offset: ['250px', '300px'], btn: ['知道了'], btnAlign: 'c'});
						document.getElementById("modal_div").style.display = "none";
					}
				},
				error: function(error, ab, cd) {
					layer.close(loadding);
					//console.log(error);
					//for(a in error){
                    //   alert(a + "-" + error[a]);
					//}
					layer.msg('充值接口异常,请重试!', {icon: 5, time: 500000, offset: ['250px', '300px'], btn: ['知道了'], btnAlign: 'c'});
					document.getElementById('rechargeSelect').style.display = "block";
					document.getElementById('rechargeSelect2').style.display = "none";
				}
			}
		);
	}
	function closeRecharge(){
		clearInterval(payInterval)
		layer.close(rechargeModal)
	}
	function openRecharge()
	{
		// 在此处输入 layer 的任意代码
		rechargeModal = layer.open({
			type: 1, // page 层类型
			area: ['500px', '430px'],
			title: '荣光支付宝在线赞助渠道(平台手续费率: 0.6%,仅支持支付宝扫码付款)',
			closeBtn: 2,
			shade: 0.6, // 遮罩透明度
			shadeClose: false, // 点击遮罩区域，关闭弹层
			maxmin: false, // 允许全屏最小化
			anim: 5, // 0-6 的动画形式，-1 不开启
			cancel: function(){ 
				//右上角关闭回调
				//return false 开启该代码可禁止点击该按钮关闭
				clearInterval(payInterval)
			},
			// content: '<div id="rechargeSelect" style="display: block;">' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs2"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs8"><div class="grid-demo grid-demo-bg1">请选择赞助金额(本次赞助账号: <font style="color:#F00;"><?php echo $_SESSION['AccountID']; ?></font>)</div></div><div class="layui-col-xs2"><div class="grid-demo">　</div></div></div>' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs2"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs8"><div class="grid-demo grid-demo-bg1"><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(50)">50</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(100)">100</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(200)">200</button></div></div><div class="layui-col-xs2"><div class="grid-demo">　</div></div></div>' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs2"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs8"><div class="grid-demo grid-demo-bg1"><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(500)">500</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(1000)">1000</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(2000)">2000</button></div></div><div class="layui-col-xs2"><div class="grid-demo">　</div></div></div>' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs2"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs8"><div class="grid-demo grid-demo-bg1"><input id="rechargeNumber" type="number" lay-affix="number" placeholder="请输入任意赞助金额(5元以上)" value="" class="layui-input" /><br /><button type="button" class="layui-btn layui-bg-blue" onclick="generateRechargeQr()">确认充值</button></div></div><div class="layui-col-xs2"><div class="grid-demo">　</div></div></div>' + 
			// '</div>' + 
			// '<div id="rechargeSelect2" style="display: none;">' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs3"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs6"><div class="grid-demo grid-demo-bg1" style="text-align: center;"><img id="rechargeImg" src=""></div></div><div class="layui-col-xs3"><div class="grid-demo">　</div></div></div>' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs2"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs10"><div class="grid-demo grid-demo-bg1">正在为账号: <font style="color:#F00;"><?php echo $_SESSION['AccountID']; ?></font> 进行赞助, 赞助金额: <a id="rechargeNumDisplay" style="color:#F00;">123元</a>, 请确认后再扫码支付</div></div></div>' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs2"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs10"><div class="grid-demo grid-demo-bg1">平台收取手续费:<a id="recharExtMoneyNumDisplay" style="color:#F00;"></a>(费率:<font style="color:#F00;">0.6%</font>), 实际需要支付金额: <a id="rechargeAllMoney" style="color:#F00;"></a><a></div></div><div class="layui-col-xs2"><div class="grid-demo">　</div></div></div>' + 
			// '<br /><div class="layui-row"><div class="layui-col-xs2"><div class="grid-demo grid-demo-bg1">　</div></div><div class="layui-col-xs8"><div class="grid-demo grid-demo-bg1">遇到任何问题,请联系客服QQ:719079746</div></div><div class="layui-col-xs2"><div class="grid-demo">　</div></div></div>' + 
			// '</div>'
			content: '<div id="rechargeSelect" style="display: block;">' + 
			'<br /><div style="padding-left:100px;">请选择赞助金额(本次赞助账号: <font style="color:#F00;"><?php echo $_SESSION['AccountID']; ?></font>)</div>' + 
			'<br /><div style="padding-left:100px;"><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(50)">50</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(100)">100</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(200)">200</button></div>' + 
			'<br /><div style="padding-left:100px;"><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(500)">500</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(1000)">1000</button><button class="layui-btn layui-btn-primary layui-border-blue rechargeBtn" onclick="clickMoneyBtn(2000)">2000</button></div>' + 
			'<br /><div style="padding-left:100px;" class="rechargeInput"><input id="rechargeNumber" type="number" lay-affix="number" placeholder="请输入任意赞助金额(5元以上)" value="" class="layui-input" /></div>' + 
			'<br /><div style="padding-left:100px;"><button type="button" class="layui-btn layui-bg-blue" onclick="generateRechargeQr()">确认充值</button><button type="button" class="layui-btn layui-btn-danger" onclick="closeRecharge()">关闭</button></div>' + 
			'</div>' + 
			'<div id="rechargeSelect2" style="display: none;">' + 
			'<br /><div style="text-align: center"><img id="rechargeImg" src=""></div>' + 
			'<div style="text-align: center"><a id="payStatusDislpay" style="color:#F00;">等待支付</a><button type="button" id="payStatusRefreshBtn" style="display: none" class="layui-btn layui-bg-blue" onclick="payStatusRefresh()">点我刷新余额</button></div>' + 
			'<br /><div style="text-align: center">正在为账号: <font style="color:#F00;"><?php echo $_SESSION['AccountID']; ?></font> 进行储值, 赞助金额: <a id="rechargeNumDisplay" style="color:#F00;">123元</a>, 请确认账号正确后再支付</div>' + 
			'<br /><div style="text-align: center">平台收取手续费: <a id="recharExtMoneyNumDisplay" style="color:#F00;"></a>(费率: <font style="color:#F00;">0.6%</font>), 实际需要支付金额: <a id="rechargeAllMoney" style="color:#F00;"></a></div>' + 
			'<br /><div style="text-align: center">遇到任何问题,请联系客服QQ:719079746</div>' + 
			'</div>'



		});
	}
</script>
<!--<script type="text/javascript" src="js/jquery.js"></script>-->
<script type="text/javascript">
	var click_status = true;//防止重复点击
	var buy = true;
	//购买确认框
	function buy_sdj(index) {
		$(".popupdiv").removeClass("zengsong").addClass("goumai");
		document.getElementById("modal_div").style.display = "block";
		document.getElementById("select_div").style.display = "none";
		document.getElementById("current_image").src = document.getElementById("image_" + index).src;
		document.getElementById("current_name").innerHTML = document.getElementById("name_" + index).innerHTML;
		document.getElementById("show_price").innerHTML = "售价 : " + document.getElementById("price_" + index).innerHTML;
		document.getElementById("current_price").value = document.getElementById("price_" + index).innerHTML;
		document.getElementById("current_item").value = document.getElementById("item_" + index).value;
		document.getElementById("current_idx").value = document.getElementById("idx_" + index).value;
		//document.getElementById("current_jieshao").innerHTML = document.getElementById("jieshao_" + index).innerHTML;
		document.getElementById("current_alt").innerHTML = document.getElementById("alt_" + index).value;
		document.getElementById("confirm_button").innerHTML = "确定购买";
		buy = true;
	}

	function readxq(index_goods,dengji,wuligongji,mofagongji,wulifangyu,mofafangyu,mingzhong,huibi,liliang,minjie,zhihui,hp,mp,type){
		//document.getElementById("number_xq").value = index_goods;
		//console.log(document.getElementById("number_xq").value);
		var goods_jieshao1 = document.getElementById("alt_"+index_goods).value;
		var goods_image1 = document.getElementById("image_"+index_goods).src;
		var goods_name1 = document.getElementById("name_"+index_goods).getAttribute("data_value");
		var goods_price1 = document.getElementById("price_"+index_goods).getAttribute("data_value");
		if ( type != 2 )
		{
			return false;
		}
		//console.log("name_"+index_goods);
		layer.config({
			extend: 'mycss/main.css', //加载您的扩展样式
			skin: 'tm_class'
		});
		//layer.alert('layer皮肤-Yourskin');
		layer.open({
			type: 1
			,skin:'tm_class'
			,title: [goods_name1 + ' - 详细信息','background-color:#8bc34a'] //不显示标题栏
			,closeBtn: false
			,offset: ['40px', '250px']
			,area: ['360px','500px']
			,shade: 0.8
			,id: 'LAY_layuipro' //设定一个id，防止重复弹出
			,resize: false
			,btn: ['购买','赠送','关闭']
			//点击回调
			,yes: function(index, layero){
				//事件
				//console.log(index)
				layer.close(index);
				buy_sdj(index_goods);
			}
			,btn2: function(index, layero){
				//按钮【按钮二】的回调
				layer.close(index);
				gift_send(index_goods);
			}
/////////////////////////
			,btnAlign: 'c'
			,moveType: 1 //拖拽模式，0或者1
			,content:
			'<div id="tm_class"><div style = "text-align:left;padding-left:10px;float:left;width:120px;"><img src="'+goods_image1+'"></div>'+
			'<div style="float:left;width:230px;height:87px;text-align:center;line-height:87px">'+goods_name1+'</div>'+
			'<p style="padding-left:8px"><font color = "	#FF7F50">售价 :</font> <font color="green">'+goods_price1+'</font> <font color = "#FF7F50">荣币</font></p>'+
			'<div style="float:left;width:150px;padding-left:8px"><p id="item_name">职业:人类</p>'+
			'<p>所需等级 : '+dengji+'</p>'+
			'<p>物理攻击 : '+wuligongji+'</p>'+
			'<p>物理防御 : '+wulifangyu+'</p>'+
			'<p>魔法攻击 : '+mofagongji+'</p>'+
			'<p>魔法防御 : '+mofafangyu+'</p>'+
			'<p>命中值   : '+mingzhong+'</p>'+
			'<p>回避值   : '+huibi+'</p>'+
			'<p>力量     : '+liliang+'</p>'+
			'<p>敏捷     : '+minjie+'</p>'+
			'<p>智力     : '+zhihui+'</p>'+
			'<p>HP增加量 : '+hp+'</p>'+
			'<p>MP增加量 : '+mp+'</p>'+
			'</div>'+
			'<div style="float:left;width:200px;line-height:18px;"><font style ="padding-left:10px;display:block;padding-top:10px;" size="2px;">详细介绍:<br>'+goods_jieshao1+'</font></br></div>'+
			'</div>'

		});
	}
	///////////////////////////////////
	/////////////////////



	//赠送模块
	var haopengyou = "";
	var loadding = 99999 ;
	function confirm_buy() {
		var price = document.getElementById("current_price").value;
		var itemNo = document.getElementById("current_item").value;
		var id_x = document.getElementById("current_idx").value;
		if (buy) {
			haopengyou = "";
		} else {
			//                var oSelect = document.getElementById('friend_id');
			//                var index = oSelect.selectedIndex;   //option数组返回的同时会返回当前option的选中下标selectedIndex
			//                var haopengyou = oSelect[index].value;
		}
		if( !click_status )//防止重复点击
		{
			//console.log(1);
			return;
		}
		click_status = false;
		close_div();
//		loadding = layer.load(2, {
//			shade: [0.1,'#fff'],//0.1透明度的白色背景
//			offset: ['150px', '300px']
//		});
		loadding = layer.msg('处理中...', {
			icon: 16
			,shade: [0.8, '#393D49'],
			offset: ['150px', '300px']
		});
		$.ajax({
				type: "POST",
				url: "api/cart.php",
				dataType: "json",
				data: {
					action: 'confirmBuy',
					price: price,
					itemNo: itemNo,
					id_x: id_x,
					buy: buy,
					haoyou: haopengyou
				},
				success: function(data) {
					click_status = true;//放开点击
					if (data.code == 0) {
						if (buy) {
							//                            alert("购买成功");
							//layer.msg('购买成功,请从右下角MY ITEM提取', 5);
							if(data.sendpoint > 0 )
							{
								layer.msg('道具已发送至右下角MY ITEM,本次消费获赠:'+ data.sendpoint +'点积分.', {icon: 1, time: 500000, offset: ['150px', '300px'], btn: ['知道了'], btnAlign: 'c'});
							}else
							{
								layer.msg('道具已发送至右下角MY ITEM', {icon: 1, time: 500000, offset: ['150px', '300px'], btn: ['知道了'], btnAlign: 'c'});
							}
						} else {
							// alert("赠送成功");
							//layer.msg('赠送成功', 5);
							if( data.sendpoint > 0 )
							{
								layer.msg('道具已发送至好友MY ITEM,本次消费获赠:'+ data.sendpoint +'点积分.', {icon: 1, time: 500000, offset: ['150px', '300px'], btn: ['知道了'], btnAlign: 'c'});
							}else
							{
								layer.msg('道具已发送至好友MY ITEM', {icon: 1, time: 500000, offset: ['150px', '300px'], btn: ['知道了'], btnAlign: 'c'});
							}
						}
						document.getElementById("modal_div").style.display = "none";
						document.getElementById("balance_show").innerHTML = data.balance;
					} else {
						//                        alert(data.msg);
						document.getElementById("modal_div").style.display = "none";
						var notEnoughMoneyLayerMsg = layer.msg(data.msg, {icon: 2, time: 3000, offset: ['150px', '300px'], btn: ['知道了'], btnAlign: 'c'});
						// 余额不足调起支付
						setTimeout(function () {
							layer.close(notEnoughMoneyLayerMsg);
							openRecharge();
						}, 3000)
					}
				},
				error: function(error, ab, cd) {
					console.log(error);
				}
			}
		);
	}
	function gift_send(index) {
		<?php
		if ($friends_count > 0) {
		?>
		$(".popupdiv").removeClass("goumai").addClass("zengsong");
		document.getElementById("modal_div").style.display = "block";
		document.getElementById("select_div").style.display = "block";
		document.getElementById("current_image").src = document.getElementById("image_" + index).src;
		document.getElementById("current_name").innerHTML = document.getElementById("name_" + index).innerHTML;
		document.getElementById("show_price").innerHTML = "售价 : " + document.getElementById("price_" + index).innerHTML;
		document.getElementById("current_price").value = document.getElementById("price_" + index).innerHTML;
		document.getElementById("current_item").value = document.getElementById("item_" + index).value;
		document.getElementById("current_idx").value = document.getElementById("idx_" + index).value;
		//document.getElementById("current_jieshao").innerHTML = document.getElementById("jieshao_" + index).innerHTML;
		document.getElementById("current_alt").innerHTML = document.getElementById("alt_" + index).value;
		document.getElementById("confirm_button").innerHTML = "确定赠送";
		buy = false;
		<?php
		} else {

		?>
		layer.msg('你暂时没有好友', {icon: 2, time: 500000, offset: ['150px', '300px'], btn: ['知道了'], btnAlign: 'c'});
		<?php
		}
		?>
		/*
		 layer.msg("即将开通，敬请期待", 5);*/
	}
	function close_div() {
		document.getElementById("modal_div").style.display = "none";
	}
	function selectli(e) {
		var lis = document.getElementsByTagName("li");
		for (var i = 0; i < lis.length; i++) {
			lis[i].className = "";
		}
		e.className = "selected";
		haopengyou = e.id;
	}
</script>
</html>